package rest.jbpm.svg;

/**
 * Created by IntelliJ IDEA.
 * User: xEviL
 * Date: 26.10.11
 * Time: 15:06
 * To change this template use File | Settings | File Templates.
 */
class JbpmCircleElement extends JbpmElement{
    protected Double r = 0.0;

    public JbpmCircleElement(String _name, Integer _x, Integer _y, Integer _w, Integer _h){
        super(_name,_x,_y,_w,_h);
        r = w/2.0;
    }

    public String draw(){
       String strokeColor = "black";
       if (active){
           strokeColor = "red";
       }
       return "<circle cx=\""+(x+w/2)+"\" cy=\""+(y+w/2)+"\" r=\""+r+"\"" +
               "  style=\"fill:white;stroke:"+strokeColor+";stroke-width:2;fill-opacity:1;\n" +
               "  stroke-opacity:0.9\"/>\n";/* +
               "<text x=\""+(x+(w/2))+"\" y=\""+(y+(h/2))+"\" font-family=\"sans-serif\" fill=\"red\" style=\"text-anchor:middle;dominant-baseline:central;\">"+name+"</text>";*/
    }

    public Integer getBorderX(Integer dX, Integer dY){
        //
        Integer cX = getElCenterX();
        Integer cY = getElCenterY();

        //
        double tgA = (((double) (dY-cY) / (double)(dX-cX)));
        double A = Math.atan( tgA );

        return  (int)Math.round((cX - (cX-dX)/Math.abs(cX-dX)*Math.abs(r*Math.cos(A))));
    }

    public Integer getBorderY(Integer dX, Integer dY){
        //
        Integer cX = getElCenterX();
        Integer cY = getElCenterY();

        //
        double tgA = (((double) (dY-cY) / (double)(dX-cX)));
        double A = Math.atan( tgA );

        return  (int)Math.round((cY - (cY-dY)/Math.abs(cY-dY)*Math.abs(r*Math.sin(A))));
    }
}
